﻿using System;
using JTLeigh.Commerce.Spencer.Core.Testing;
using JTLeigh.Commerce.Spencer.Features.ProductFeedback.Common.Entities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace JTLeigh.Commerce.Spencer.Features.ProductFeedback.Common.UnitTests.Entities
{

	/// <summary>
	/// Unit tests for the <see cref="LocalizedProductRecommendationAttribute"/> class.
	/// </summary>
	[TestClass]
	public class LocalizedProductRecommendationAttributeFixture
	{

		#region Methods

		/// <summary>
		/// Ensures <see cref="LocalizedProductRecommendationAttribute"/> returns localized and 
		/// attribute values for its localizable and attribute fields when its constructor is 
		/// passed <see cref="ProductRecommendationAttributeLocalization"/> and
		/// <see cref="ProductRecommendationAttributeProductAssociation"/> objects.
		/// </summary>
		[TestMethod]
		public void TestLocalizedProductRecommendationAttributeOperationWithLocalizationAssociation()
		{
			ProductRecommendationAttribute attribute;
			ProductRecommendationAttributeLocalization localization;
			ProductRecommendationAttributeProductAssociation association;
			LocalizedProductRecommendationAttribute localizedAttribute;

			attribute = new ProductRecommendationAttribute
			{
				AttributeId = Guid.NewGuid(),
				DefaultText = "defaultText",
			};
			localization = new ProductRecommendationAttributeLocalization
			{
				AttributeId = attribute.AttributeId,
				CultureId = TestConstants.CultureId.EnglishCanada,
				Text = "localizedText",
			};
			association = new ProductRecommendationAttributeProductAssociation
			{
				DisplayOrder = 5,
			};

			localizedAttribute = new LocalizedProductRecommendationAttribute(attribute, localization, association);

			Assert.AreEqual(attribute.AttributeId, localizedAttribute.AttributeId);
			Assert.AreEqual(localization.Text, localizedAttribute.Text);
			Assert.AreEqual(association.DisplayOrder, localizedAttribute.DisplayOrder);
		}

		/// <summary>
		/// Ensures <see cref="LocalizedProductRecommendationAttribute"/> returns default values 
		/// for its localizable and attribute fields when its constructor is passed <see langword="null"/> 
		/// values instead of <see cref="ProductRecommendationAttributeLocalization"/> and
		/// <see cref="ProductRecommendationAttributeProductAssociation"/> objects.
		/// </summary>
		[TestMethod]
		public void TestLocalizedProductRecommendationAttributeOperationWithoutLocalizationAssociation()
		{
			ProductRecommendationAttribute attribute;
			LocalizedProductRecommendationAttribute localizedAttribute;

			attribute = new ProductRecommendationAttribute
			{
				AttributeId = Guid.NewGuid(),
				DefaultText = "defaultText",
			};

			localizedAttribute = new LocalizedProductRecommendationAttribute(attribute, null, null);

			Assert.AreEqual(attribute.AttributeId, localizedAttribute.AttributeId);
			Assert.AreEqual(attribute.DefaultText, localizedAttribute.Text);
			Assert.AreEqual(0, localizedAttribute.DisplayOrder);
		}

		#endregion // Methods

	}

}
